package com.xm.servlet.reception_desk.shopping_cart;

import com.google.gson.Gson;
import com.xm.service.reception_desk.CommodityInsuranceService;
import lombok.SneakyThrows;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 查询商品条款详细
 * @author 康文程
 * @date 2024-1-6 下午 06:24
 */
@WebServlet("/purchase/merchandise/insurance")
public class PurchaseMerchandiseInsurance extends HttpServlet {
    private final CommodityInsuranceService service = new CommodityInsuranceService();

    /**
     * 根据商品Id查询商品条款
     * @param req   an {@link HttpServletRequest} object that
     *                  contains the request the client has made
     *                  of the servlet
     *
     * @param resp  an {@link HttpServletResponse} object that
     *                  contains the response the servlet sends
     *                  to the client
     *
     */
    @SneakyThrows(Exception.class)
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) {
        resp.setContentType("text/html;charset=utf-8");
        String insuranceId = req.getParameter("insuranceId");
        System.out.println(insuranceId);
        resp.getWriter().println(new Gson().toJson(service.getInsuranceWithRelatedTablesById
                (Integer.parseInt(insuranceId))));
    }
}
